package com.yc.io;

import java.io.*;
import java.util.EnumSet;

/**
 * Title: 读取本地文件 <br>
 * Description: <br>
 * Author:陈圆(chenyuan@bosssoft.com.cn) <br>
 * Date:2020/9/10
 */
public class FileReadDemo {

    public static void main(String[] args) {
        try {
            FileInputStream fileInputStream
//                    = new FileInputStream("d:\\a.txt"); // 文件流
                    = new FileInputStream("/Users/samuelchen/desktop/channel.txt"); // 文件流
            InputStreamReader isr
                    = new InputStreamReader(fileInputStream);//字符流
            BufferedReader br
                    = new BufferedReader(isr); //缓冲

            Reader brffer = new BufferedReader(new InputStreamReader(new FileInputStream("/Users/samuelchen/desktop/channel.txt")));
            String line = null;
            while( (line=br.readLine())!=null ){//字符不等于空
                System.out.println(line);//一行一行地du输出
            }
            br.close();//关闭文件
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * Create collection.
     *
     * @param <E>            the type parameter
     * @param collectionType the collection type
     * @param elementType    the element type
     * @param capacity       the capacity
     * @return the collection

    @SuppressWarnings("unchecked")
    public <E> Collection<E> create(final Class<?> collectionType, final Class<?> elementType, final int capacity) {
        if (collectionType.isInterface()) {
            if (Set.class == collectionType || Collection.class == collectionType) {
                return new LinkedHashSet<>(capacity);
            } else if (List.class == collectionType) {
                return new ArrayList<>(capacity);
            } else if (SortedSet.class == collectionType || NavigableSet.class == collectionType) {
                return new TreeSet<>();
            } else {
                throw new IllegalArgumentException("Unsupported Collection interface: " + collectionType.getName());
            }
        } else if (EnumSet.class == collectionType) {
            // Cast is necessary for compilation in Eclipse 4.4.1.
            return (Collection<E>) EnumSet.noneOf(asEnumType(elementType));
        } else {
            if (!Collection.class.isAssignableFrom(collectionType)) {
                throw new IllegalArgumentException("Unsupported Collection type: " + collectionType.getName());
            }
            try {
                return (Collection<E>) collectionType.newInstance();
            } catch (Throwable ex) {
                throw new IllegalArgumentException(
                        "Could not instantiate Collection type: " + collectionType.getName(), ex);
            }
        }
    }
     */
}
